/**
 * Created by Administrator on 2017/5/4 0004.
 */
//截取参数
checkCookie();
var mid= $.cookie('mid')
var token= $.cookie('token')

var mydate=new Date();
var month=mydate.getMonth()+1;
var date=mydate.getDate();
var week=mydate.getDay();
var arr=['周日','周一','周二','周三','周四','周五','周六','周日','周一','周二','周三','周四','周五','周六'];
for(var i=0;i<7;i++){
    $('.date1 li').eq(i).find('.week').html(arr[week+i]);
    $('.date1 li').eq(i).find('.month_date').html(month+'-'+(date+i))
}
$('.date1 li').find('.week').eq(0).html('今天');
$('.date1 li').find('.month_date').eq(0).html(month+'-'+date);
var searchURL = window.location.search;
searchURL = searchURL.substring(1, searchURL.length);
var d_id = searchURL.split("&")[0].split("=")[1];

var next_page='';
var data_back=false;
$(window).scroll(function () {
    var windowheight=$(window).height();//窗口高度
    var scrolltop=$('body').scrollTop();//滚动条高度
    var eh=$(document).height();//文本高度
    if(eh==windowheight+scrolltop){
        $('.bot_loading').show()
        if(data_back){
            return false
        }
        data_back=true;
            if(next_page==null){
                $('.bot_loading').html('没有更多啦！');
                setInterval(function () {
                    $('.bot_loading').fadeOut(800)
                },2000);
                data_back=false
            }else{
                getData({url:next_page+'&id='+d_id,data:{mid:mid,token:token}}, function (data) {
                    var html=template('comment_list',data);
                    $('.comment_list').append(html)
                    $('.bot_loading').hide();
                    next_page=data.comment.data.next_page_url
                    data_back=false
                })

            }

    }else{
        $('.bot_loading').hide()
    }
})

    getData({url:doctor_info,data:{mid:mid,token:token,id:d_id}}, function (data) {
           var html=template('doctor',data);
           $('#main').html(html);
            var childs=$('.comment_list').find('li')
            if(childs.length==0){
                $('.comment').append('<p style="text-align: center;padding-top: 10px">暂无评论</p>')
            }
        next_page=data.comment.data.next_page_url;
        //点击关注
            $('.guanzhu').on('touchstart', function () {
                getData({url:follow,type:'post',data:{mid:mid,token:token,d_id:d_id}}, function () {
                    $('.guanzhu').html('已关注').css({'color':'#777777','borderColor':'#777777'})
})
});
        //点击预约
        $('.yuyue').on('touchstart', function () {
            $('#all').show();
            $('body').css('position','fixed');
            var doc_id=$(this).attr('d_id');
           // console.log(doc_id)

           getData({url:yuyue,data:{mid:mid,token:token,id:doc_id}}, function (data) {
                var html=template('yuyue',data);
                $('.box_top').html(html);
               var htmlone=template('choose_date',data);
               $('.choose_time ul').html(htmlone)
               //点击日期发起请求
               $('.date1_list li').on('touchstart', function () {
                   $('.choose_time ul').html('');
                   var key1= $(this).index();
                   getData({url:yuyue,data:{mid:mid,token:token,id:doc_id,key:key1}}, function (data) {
                       var htmlone=template('choose_date',data);
                       $('.choose_time ul').html(htmlone);
                   });
               })
               $('.yy').on('touchstart', function () {
                   var key2= $('#all .tag').parent().index();
                   // localStorage.work_time=$(this).attr('work_time')//localStorage预约时间
                   var time=$(this).attr('work_time')
                   window.location.href='finish-reference.html?d_id='+doc_id+'&time='+time+'&key='+key2;
               })
               //循环日期
               var myScroll=new iScroll('wrapper',{
                   vScroll:false,
                   hScroll:true
               })
               //tab切换日期
               $('.date_active').on('touchstart', function () {
                   $(this).siblings().find('div').removeClass('tag');
                   $(this).find('div').addClass('tag');
//                   getData({url:,data:{}})
})

})
})

});
$('.close').on('touchstart', function () {
    $('#all').hide();
    $('body').css('position','');
    $('.comment_list li').css('pointer-events','none');
    setTimeout(function () {
        $('.comment_list li').css('pointer-events','auto');
    },400)
});

